#pragma once
#include "ScalarStorage.h"
#include "index_factory.h"
#include <rapidjson/document.h>
#include "constants.h"
#include "persistence.h"

class VectorDatabase {
public:
    VectorDatabase(const std::string& db_path,const std::string& wal_path);
    // 插入或更新向量
    void upsert_vectors(uint64_t id,const rapidjson::Document& data,IndexFactory::IndexType index_type);
    rapidjson::Document query(uint64_t id);
    std::pair<std::vector<long>,std::vector<float>> search(const rapidjson::Document& json_request);
    IndexFactory::IndexType getIndexTypeFromReq(const rapidjson::Document& json_request);
    // 日志操作
    void reloadDatabase();
    void writeWALLog(const std::string& operation_type,const rapidjson::Document& json_data);

    void writeWALLogWithID(uint64_t id,const std::string&data);
    void takeSnapshot();
    int64_t getStartIndexID()const;
private:
    ScalarStorage scalar_storage_;
    Persistence persistence_;
};